package com.ywjg.serviceimp;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.ywjg.dao.GoodFavoriteDao;
import com.ywjg.model.GoodFavorite;
import com.ywjg.service.IGoodFavoriteService;
@Service
public class GoodFavoriteService implements IGoodFavoriteService {
	@Resource
	GoodFavoriteDao goodFavoriteDao;

	/* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IGoodFavoriteService#getMyGoodFavorite(java.lang.Integer, int, int)
	 */
	public List<GoodFavorite> getMyGoodFavorite(Integer userId) {
		Pageable pageable = new PageRequest(0, 100);
		List<GoodFavorite> goodFavorites = goodFavoriteDao.findByUserId(userId, pageable);
		return goodFavorites;
	}

	/* (non-Javadoc)
	 * @see com.ywjg.serviceimp.IGoodFavoriteService#deleteOneGoodFavorite(com.ywjg.model.GoodFavorite)
	 */
	public void deleteOneGoodFavorite(int goodId) {
		// TODO Auto-generated method stub
		GoodFavorite goodFavorite = goodFavoriteDao.findBygoodId(goodId);
		goodFavoriteDao.delete(goodFavorite);
	}
	
	
	public GoodFavorite addOneGoodFavorite(GoodFavorite goodFavorite) {
		// TODO Auto-generated method stub
		GoodFavorite save=null;
		GoodFavorite findGoodFavorite = goodFavoriteDao.findByGoodIdAndUserId(goodFavorite.getGoodId(), goodFavorite.getUserId());
		if (null==findGoodFavorite) {
		    save = goodFavoriteDao.save(goodFavorite);
		}
		return save;
	}
}
